'''###########################################################################################################################
### File: animation.py
### Name: Patrick Delaney, Andrew Oberlin
### Class: CSE 487
### Instructor: Dr.Zmuda
### Assignment: Final Project
### Description: Class for animation objects
################ 
'''
import cPickle as serialize

class Animation:
	'''
	### Name: __init__ (Constructor)
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Sets the name for this level
	'''
	def __init__(self):
		self.name = ""
		self.type = ""
		self.numFrames = 0
		self.textures = []
		
	'''
	### Name: addTexture
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Adds a texture to this animation
	'''
	def addTexture(self, texture):
		self.textures.append(texture)
		self.numFrames += 1
		
	'''
	### Name: getTextures
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Gets the textures for this animation
	'''
	def getTextures(self):
		return self.textures
		
	'''
	### Name: setName
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Sets the name for this animation
	'''
	def setName(self, name):
		self.name = name.capitalize()
		
	'''
	### Name: getName
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Gets the name for this animation
	'''
	def getName(self):
		return self.name
		
	'''
	### Name: setName
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Sets the type for this animation
	'''
	def setType(self, type):
		self.type = type
		
	'''
	### Name: getType
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Gets the type for this animation
	'''
	def getType(self):
		return self.type
	
	'''
	### Name: setNumFrames
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Sets the numFrames for this animation
	'''
	def setNumFrames(self, numFrames):
		self.numFrames = numFrames
		
	'''
	### Name: getNumFrames
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Gets the numFrames for this animation
	'''
	def getNumFrames(self):
		return self.numFrames
	
	'''
	
	'''
	def exportAsTexturesList(self, parent):
		textureList = []
		for texture in self.textures:
			textureList.append(parent.loader.loadTexture(texture))
			
		return textureList
	
	'''
	### Name: save
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Saves this character as a serialized file
	###				 with name 'projects/<projectName>/characters/main/<name>.char' 
	###				 **name attribute required**
	'''
	def save(self, projectName, mainCharName):
		if (self.name):
			file = open( "projects/" + projectName + "/characters/main/" + mainCharName + "/" + self.name +  ".anim", "wb" )
			serialize.dump(self, file, 1)
			
	'''
	### Name: load
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Loads the character from a serialized file
	###				 with name 'projects/<projectName>/characters/main/<name>.char'
	'''
	def load(self, path):
		try:
			file = open( path, "rb" )
			newSelf = serialize.load(file)
			self.copy(newSelf)
		except IOError, e:
			print "Problem loading the level"
			print e
			
	'''
	### Name: copy
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Copies the newSelf's attributes to self
	'''
	def copy(self, newSelf):
		self.name = newSelf.name
		self.type = newSelf.type
		self.numFrames = newSelf.numFrames
		self.textures = newSelf.textures